package com.tsll.common;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.tsll.domain.*;
import com.tsll.enums.SmsInterfaceType;
import com.tsll.exception.ServiceException;

import java.io.IOException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 阿里云短信工具类
 */
public class AliYunSmsUtils {

    //阿里云短信服务器区域类型
    private static final String REGION_ID = "cn-hangzhou";
    //阿里云短信请求地址
    private static final String ALIYUN_IP = "dysmsapi.aliyuncs.com";
    //阿里云短信服务版本号
    private static final String VERSION = "2017-05-25";

    // ========================短信发送======================================

    /**
     * 发送短信
     *
     * @param smsRequest 通用短信发送参数
     * @return
     */
    public static AjaxResult startSendSms(SmsRequest smsRequest) {
        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = getCommonRequest(SmsInterfaceType.SEND_SMS);
        //初始化阿里云短信接收结果消息体
        CommonResponse commonResponse = null;

        //初始化设置阿里云用户唯一标识和短信服务器区域类型(用来认证用户的)
        DefaultProfile defaultProfile = DefaultProfile.getProfile(REGION_ID, smsRequest.getAccessKeyID(), smsRequest.getAccessKeySecret());
        IAcsClient iAcsClient = new DefaultAcsClient(defaultProfile);

        //设置接收短信的手机号码
        commonRequest.putQueryParameter("PhoneNumbers", smsRequest.getPhoneNumber());
        //设置阿里云短信模板签名
        commonRequest.putQueryParameter("SignName", smsRequest.getSignName());
        //设置阿里云短信模板code
        commonRequest.putQueryParameter("TemplateCode", smsRequest.getTemplateCode());
        //设置短信内容
        commonRequest.putQueryParameter("TemplateParam", parsingKeyValue(smsRequest.getMapContent()));
        try {
            //确认发送短信
            commonResponse = iAcsClient.getCommonResponse(commonRequest);
        } catch (ClientException e) {
            e.printStackTrace();
            return AjaxResult.error("网络错误");
        }//参数配置校验未通过错误

        if(commonResponse.getHttpStatus()==200){
            JSON json = JSONUtil.parse(commonResponse.getData());
            if("OK".equals(json.getByPath("Code"))){
                return AjaxResult.success("发送成功");
            }
            return AjaxResult.error(json.getByPath("Message").toString());
        }
        return AjaxResult.error("网络错误");
    }

    /**
     * 批量发送短信
     *
     * @param batchSmsRequest 通用请求
     * @return
     */
    public static AjaxResult startSendBatchSms(BatchSmsRequest batchSmsRequest) {
        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = getCommonRequest(SmsInterfaceType.BATCH_SEND_SMS);
        //初始化阿里云短信接收结果消息体
        CommonResponse commonResponse = null;

        //初始化设置阿里云用户唯一标识和短信服务器区域类型(用来认证用户的)
        DefaultProfile defaultProfile = DefaultProfile.getProfile(REGION_ID, batchSmsRequest.getAccessKeyID(), batchSmsRequest.getAccessKeySecret());
        IAcsClient iAcsClient = new DefaultAcsClient(defaultProfile);

        //设置接收短信的手机号码
        commonRequest.putQueryParameter("PhoneNumberJson", JSONUtil.toJsonStr(batchSmsRequest.getPhoneNumber()));
        //设置阿里云短信模板签名
        commonRequest.putQueryParameter("SignNameJson", JSONUtil.toJsonStr(batchSmsRequest.getSignName()));
        //设置阿里云短信模板code
        commonRequest.putQueryParameter("TemplateCode", batchSmsRequest.getTemplateCode());
        //设置短信内容
        commonRequest.putQueryParameter("TemplateParamJson", JSONUtil.parseArray(batchSmsRequest.getMapContent()).toString());
        try {
            //确认发送短信
            commonResponse = iAcsClient.getCommonResponse(commonRequest);
        } catch (ClientException e) {
            e.printStackTrace();
            return AjaxResult.error("网络错误");
        }
        if(commonResponse.getHttpStatus()==200){
            JSON json = JSONUtil.parse(commonResponse.getData());
            if("OK".equals(json.getByPath("Code"))){
                return AjaxResult.success("发送成功");
            }
            return AjaxResult.error(json.getByPath("Message").toString());
        }
        return AjaxResult.error("网络错误");
    }

    /**
     * 查询指定日期下的指定/所有短信
     *
     * @param hisRequest 查询历史请求参数
     * @return
     */
    public static AjaxResult startQuerySendDetails(SendHisRequest hisRequest) {
        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = getCommonRequest(SmsInterfaceType.QUERY_SEND_DETAILS);
        //初始化阿里云短信接收结果消息体
        CommonResponse commonResponse = null;

        //初始化设置阿里云用户唯一标识和短信服务器区域类型(用来认证用户的)
        DefaultProfile defaultProfile = DefaultProfile.getProfile(REGION_ID, hisRequest.getAccessKeyID(), hisRequest.getAccessKeySecret());
        IAcsClient iAcsClient = new DefaultAcsClient(defaultProfile);

        //设置当前页
        commonRequest.putQueryParameter("CurrentPage", String.valueOf(hisRequest.getCurrentPage()));
        //设置每页条数
        commonRequest.putQueryParameter("PageSize", String.valueOf(hisRequest.getPageSize()));
        //设置发送短信的时间，格式 YYYYmmDD
        commonRequest.putQueryParameter("SendDate", hisRequest.getSendDate());
        //设置接收短信的手机号码
        commonRequest.putQueryParameter("PhoneNumber", hisRequest.getPhoneNumber());
        if (!StringUtils.isNotBlank(hisRequest.getBizId())) {
            commonRequest.putQueryParameter("BizId", hisRequest.getBizId());
        }
        try {
            commonResponse = iAcsClient.getCommonResponse(commonRequest);
        } catch (ClientException e) {
            e.printStackTrace();
            return AjaxResult.error("网络错误");
        }
        if(commonResponse.getHttpStatus()==200){
            JSON json = JSONUtil.parse(commonResponse.getData());
            if("OK".equals(json.getByPath("Code"))){
                Map<String,Object> map=new HashMap<>();
                map.put("TotalCount",json.getByPath("TotalCount"));
                map.put("SmsSendDetailDTO",((JSON) json.getByPath("SmsSendDetailDTOs")).getByPath("SmsSendDetailDTO"));
                return AjaxResult.success(map);
            }
            return AjaxResult.error(json.getByPath("Message").toString());
        }
        return AjaxResult.error("网络错误");
    }

    // ========================短信发送======================================



    // ===========================签名=======================================

    /**
     * 申请通用短信签名
     *
     * @param signNameRequest          短信签名申请参数
     * @return
     */
    public static AjaxResult startAddSmsSign(SignNameRequest signNameRequest) {
        //参数校验
        validatedSignNameRequest(signNameRequest);
        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = getCommonRequest(SmsInterfaceType.ADD_SMS_SIGN);
        //初始化阿里云短信接收结果消息体
        CommonResponse commonResponse = null;

        //初始化设置阿里云用户唯一标识和短信服务器区域类型(用来认证用户的)
        DefaultProfile defaultProfile = DefaultProfile.getProfile(REGION_ID, signNameRequest.getAccessKeyID(), signNameRequest.getAccessKeySecret());
        IAcsClient iAcsClient = new DefaultAcsClient(defaultProfile);

        //设置阿里云短信签名申请签名名称
        commonRequest.putQueryParameter("SignName", signNameRequest.getSignName());
        //设置阿里云短信签名申请类型
        commonRequest.putQueryParameter("SignSource", String.valueOf(signNameRequest.getSmsSignSourceType().getSignSourceId()));
        //设置阿里云短信签名申请说明
        commonRequest.putQueryParameter("Remark", signNameRequest.getRemark());
        //设置阿里云短信签名，当前图片格式
        String str = signNameRequest.getMultipartFile().getOriginalFilename();
        commonRequest.putQueryParameter("SignFileList.1.FileSuffix", str.substring(str.indexOf(".") + 1));
        try {
            //设置阿里云短信签名，当前图片的base64字符串
            commonRequest.putQueryParameter("SignFileList.1.FileContents", Base64.getEncoder().encodeToString(signNameRequest.getMultipartFile().getBytes()));
            commonResponse = iAcsClient.getCommonResponse(commonRequest);
        } catch (ClientException | IOException e) {
            e.printStackTrace();
            return AjaxResult.error("网络错误");
        }
        if(commonResponse.getHttpStatus()==200){
            JSON json = JSONUtil.parse(commonResponse.getData());
            if("OK".equals(json.getByPath("Code"))){
                return AjaxResult.success("签名已提交申请，请等待审核");
            }
            return AjaxResult.error(json.getByPath("Message").toString());
        }
        return AjaxResult.error("网络错误");
    }


    /**
     * 根据签名名称删除短信签名
     *
     * @param signNameRequest 通用请求
     * @return
     */
    public static AjaxResult startDeleteSmsSign(SignNameRequest signNameRequest) {
        if (StringUtils.isBlank(signNameRequest.getAccessKeyID())) {
            throw new ServiceException("accessKeyID不能为空");
        }
        if (StringUtils.isBlank(signNameRequest.getAccessKeySecret())) {
            throw new ServiceException("accessKeySecret不能为空");
        }
        if (StringUtils.isBlank(signNameRequest.getSignName())) {
            throw new ServiceException("签名不能为空");
        }
        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = getCommonRequest(SmsInterfaceType.DELETE_SMS_SIGN);
        //初始化阿里云短信接收结果消息体
        CommonResponse commonResponse = null;

        //初始化设置阿里云用户唯一标识和短信服务器区域类型(用来认证用户的)
        DefaultProfile defaultProfile = DefaultProfile.getProfile(REGION_ID, signNameRequest.getAccessKeyID(), signNameRequest.getAccessKeySecret());
        IAcsClient iAcsClient = new DefaultAcsClient(defaultProfile);

        //设置要删除的短信模板签名名称
        commonRequest.putQueryParameter("SignName", signNameRequest.getSignName());
        try {
            commonResponse = iAcsClient.getCommonResponse(commonRequest);
        } catch (ClientException e) {
            e.printStackTrace();
            return AjaxResult.error("网络错误");
        }
        if(commonResponse.getHttpStatus()==200){
            JSON json = JSONUtil.parse(commonResponse.getData());
            if("OK".equals(json.getByPath("Code"))){
                Map<String,Object> map = new HashMap<>();
                map.put("SignName",json.getByPath("SignName"));
                return AjaxResult.success("签名删除成功",map);
            }
            return AjaxResult.error(json.getByPath("Message").toString());
        }
        return AjaxResult.error("网络错误");
    }

    /**
     * 查询指定名称的短信签名
     *
     * @param smsRequest 通用请求
     * @return
     */
    public static AjaxResult startQuerySmsSign(SmsRequest smsRequest) {
        if (StringUtils.isBlank(smsRequest.getAccessKeyID())) {
            throw new ServiceException("accessKeyID不能为空");
        }
        if (StringUtils.isBlank(smsRequest.getAccessKeySecret())) {
            throw new ServiceException("accessKeySecret不能为空");
        }
        if (StringUtils.isBlank(smsRequest.getSignName())) {
            throw new ServiceException("签名不能为空");
        }
        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = getCommonRequest(SmsInterfaceType.QUERY_SMS_SIGN);
        //初始化阿里云短信接收结果消息体
        CommonResponse commonResponse = null;

        //初始化设置阿里云用户唯一标识和短信服务器区域类型(用来认证用户的)
        DefaultProfile defaultProfile = DefaultProfile.getProfile(REGION_ID, smsRequest.getAccessKeyID(), smsRequest.getAccessKeySecret());
        IAcsClient iAcsClient = new DefaultAcsClient(defaultProfile);

        //设置要查询的短信签名名称
        commonRequest.putQueryParameter("SignName", smsRequest.getSignName());
        try {
            commonResponse = iAcsClient.getCommonResponse(commonRequest);
        } catch (ClientException e) {
            e.printStackTrace();
            return AjaxResult.error("网络错误");
        }
        if(commonResponse.getHttpStatus()==200){
            JSON json = JSONUtil.parse(commonResponse.getData());
            if("OK".equals(json.getByPath("Code"))){
                Map<String,Object> map = new HashMap<>();
                map.put("SignStatus",json.getByPath("SignStatus"));
                map.put("SignName",json.getByPath("SignName"));
                map.put("CreateDate",json.getByPath("CreateDate"));
                map.put("Reason",json.getByPath("Reason"));
                return AjaxResult.success("查询成功",map);
            }
            return AjaxResult.error(json.getByPath("Message").toString());
        }
        return AjaxResult.error("网络错误");
    }

    // ===========================签名=======================================



    // ===========================模板=======================================

    /**
     * 申请短信模板
     *
     * @param templateNameRequest 短信模板申请参数
     * @return
     */
    public static AjaxResult startAddSmsTemplate(TemplateNameRequest templateNameRequest) {
        //参数校验
        validatedTemplateNameRequest(templateNameRequest);

        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = getCommonRequest(SmsInterfaceType.ADD_SMS_TEMPLATE);
        //初始化阿里云短信接收结果消息体
        CommonResponse commonResponse = null;

        //初始化设置阿里云用户唯一标识和短信服务器区域类型(用来认证用户的)
        DefaultProfile defaultProfile = DefaultProfile.getProfile(REGION_ID, templateNameRequest.getAccessKeyID(), templateNameRequest.getAccessKeySecret());
        IAcsClient iAcsClient = new DefaultAcsClient(defaultProfile);

        //设置阿里云短信模板申请类型
        commonRequest.putQueryParameter("TemplateType", String.valueOf(templateNameRequest.getSmsTemplateType().getTemplateTypeId()));
        //设置阿里云短信模板申请名称
        commonRequest.putQueryParameter("TemplateName", templateNameRequest.getTemplateName());
        //设置阿里云短信模板申请格式内容
        commonRequest.putQueryParameter("TemplateContent", templateNameRequest.getTemplateContent());
        //设置阿里云短信模板申请说明
        commonRequest.putQueryParameter("Remark", templateNameRequest.getRemark());
        try {
            commonResponse = iAcsClient.getCommonResponse(commonRequest);
        } catch (ClientException e) {
            e.printStackTrace();
            return AjaxResult.error("网络错误");
        }
        if(commonResponse.getHttpStatus()==200){
            JSON json = JSONUtil.parse(commonResponse.getData());
            if("OK".equals(json.getByPath("Code"))){
                Map<String,Object> map = new HashMap<>();
                map.put("TemplateCode",json.getByPath("TemplateCode"));
                return AjaxResult.success("模板已提交申请，请等待审核",map);
            }
            return AjaxResult.error(json.getByPath("Message").toString());
        }
        return AjaxResult.error("网络错误");
    }

    /**
     * 根据模板code删除短信模板
     *
     * @param templateNameRequest 通用请求
     * @return
     */
    public static AjaxResult startDeleteSmsTemplate(TemplateNameRequest templateNameRequest) {
        if (StringUtils.isBlank(templateNameRequest.getAccessKeyID())) {
            throw new ServiceException("accessKeyID不能为空");
        }
        if (StringUtils.isBlank(templateNameRequest.getAccessKeySecret())) {
            throw new ServiceException("accessKeySecret不能为空");
        }
        if (StringUtils.isBlank(templateNameRequest.getTemplateCode())) {
            throw new ServiceException("模板code不能为空");
        }
        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = getCommonRequest(SmsInterfaceType.DELETE_SMS_TEMPLATE);
        //初始化阿里云短信接收结果消息体
        CommonResponse commonResponse = null;

        //初始化设置阿里云用户唯一标识和短信服务器区域类型(用来认证用户的)
        DefaultProfile defaultProfile = DefaultProfile.getProfile(REGION_ID, templateNameRequest.getAccessKeyID(), templateNameRequest.getAccessKeySecret());
        IAcsClient iAcsClient = new DefaultAcsClient(defaultProfile);

        //设置要删除的短信模板签名名称
        commonRequest.putQueryParameter("TemplateCode", templateNameRequest.getTemplateCode());
        try {
            commonResponse = iAcsClient.getCommonResponse(commonRequest);
        } catch (ClientException e) {
            e.printStackTrace();
            return AjaxResult.error("网络错误");
        }
        if(commonResponse.getHttpStatus()==200){
            JSON json = JSONUtil.parse(commonResponse.getData());
            if("OK".equals(json.getByPath("Code"))){
                Map<String,Object> map = new HashMap<>();
                map.put("TemplateCode",json.getByPath("TemplateCode"));
                return AjaxResult.success("短信模板删除成功",map);
            }
            return AjaxResult.error(json.getByPath("Message").toString());
        }
        return AjaxResult.error("网络错误");
    }

    /**
     * 查询指定code的短信模板
     *
     * @param smsRequest 通用请求
     * @return
     */
    public static AjaxResult startQuerySmsTemplate(SmsRequest smsRequest) {
        if (StringUtils.isBlank(smsRequest.getAccessKeyID())) {
            throw new ServiceException("accessKeyID不能为空");
        }
        if (StringUtils.isBlank(smsRequest.getAccessKeySecret())) {
            throw new ServiceException("accessKeySecret不能为空");
        }
        if (StringUtils.isBlank(smsRequest.getTemplateCode())) {
            throw new ServiceException("模板code不能为空");
        }
        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = getCommonRequest(SmsInterfaceType.QUERY_SMS_TEMPLATE);
        //初始化阿里云短信接收结果消息体
        CommonResponse commonResponse = null;

        //初始化设置阿里云用户唯一标识和短信服务器区域类型(用来认证用户的)
        DefaultProfile defaultProfile = DefaultProfile.getProfile(REGION_ID, smsRequest.getAccessKeyID(), smsRequest.getAccessKeySecret());
        IAcsClient iAcsClient = new DefaultAcsClient(defaultProfile);

        //设置阿里云短信消息体请求类型
        commonRequest.setSysMethod(MethodType.POST);
        //设置阿里云短信消息体接口调用ip地址
        commonRequest.setSysDomain(ALIYUN_IP);
        //设置阿里云短信服务版本
        commonRequest.setSysVersion(VERSION);
        //设置阿里云短信请求接口类型
        commonRequest.setSysAction(SmsInterfaceType.QUERY_SMS_TEMPLATE.getType());
        //设置阿里云短信服务器区域类型
        commonRequest.putQueryParameter("RegionId", REGION_ID);
        //设置要查询的短信签名名称
        commonRequest.putQueryParameter("TemplateCode", smsRequest.getTemplateCode());
        try {
            commonResponse = iAcsClient.getCommonResponse(commonRequest);
        } catch (ClientException e) {
            e.printStackTrace();
            return AjaxResult.error("网络错误");
        }
        if(commonResponse.getHttpStatus()==200){
            JSON json = JSONUtil.parse(commonResponse.getData());
            if("OK".equals(json.getByPath("Code"))){
                Map<String,Object> map = new HashMap<>();
                map.put("TemplateCode",json.getByPath("TemplateCode"));
                map.put("TemplateName",json.getByPath("TemplateName"));
                map.put("TemplateContent",json.getByPath("TemplateContent"));
                map.put("TemplateType",json.getByPath("TemplateType"));
                map.put("CreateDate",json.getByPath("CreateDate"));
                map.put("Reason",json.getByPath("Reason"));
                map.put("TemplateStatus",json.getByPath("TemplateStatus"));
                return AjaxResult.success("查询成功",map);
            }
            return AjaxResult.error(json.getByPath("Message").toString());
        }
        return AjaxResult.error("网络错误");
    }

    // ===========================模板=======================================



    // =========================通用请求========================================

    /**
     * 所有请求通用参数
     *
     * @param smsInterfaceType
     * @return
     */
    private static CommonRequest getCommonRequest(SmsInterfaceType smsInterfaceType) {
        //初始化设置阿里云短信发送消息体
        CommonRequest commonRequest = new CommonRequest();
        //设置阿里云短信消息体请求类型
        commonRequest.setSysMethod(MethodType.POST);
        //设置阿里云短信消息体接口调用ip地址
        commonRequest.setSysDomain(ALIYUN_IP);
        //设置阿里云短信服务版本
        commonRequest.setSysVersion(VERSION);
        //设置阿里云短信请求接口类型
        commonRequest.setSysAction(smsInterfaceType.getType());
        //设置阿里云短信服务器区域类型
        commonRequest.putQueryParameter("RegionId", REGION_ID);
        return commonRequest;
    }

    // =========================通用请求========================================



    // =========================排版===========================================
    /**
     * 把短信内容进行排版，排成阿里云要求的格式
     *
     * @param mapContent
     * @return
     */
    private static String parsingKeyValue(Map<String, String> mapContent) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("{");
        for (String key : mapContent.keySet()) {
            stringBuilder.append("'" + key + "':'" + mapContent.get(key) + "',");
        }
        return stringBuilder.substring(0, stringBuilder.length() - 1) + "}";
    }



//    /**
//     * 把批量发送短信的接收手机号码进行排版，排成阿里云要求的格式
//     *
//     * @param phoneAndContentMap N个手机号码
//     * @return
//     */
//    private static String parsingPhone(Map<Map<String, SmsCodeType>, Map<String, String>> phoneAndContentMap) {
//        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append("[");
//        for (Map<String, SmsCodeType> stringSmsCodeTypeMap : phoneAndContentMap.keySet()) {
//            if (stringSmsCodeTypeMap.size() == 1) {
//                for (String key : stringSmsCodeTypeMap.keySet()) {
//                    stringBuilder.append("'" + key + "',");
//                }
//            } else {
//                throw new ArrayIndexOutOfBoundsException();
//            }
//        }
//        return stringBuilder.substring(0, stringBuilder.length() - 1) + "]";
//    }
//
//    /**
//     * 把批量发送短信的短信签名名称进行排版，排成阿里云要求的格式
//     *
//     * @param phoneAndContentMap
//     * @return
//     */
//    private static String parsingSignName(Map<Map<String, SmsCodeType>, Map<String, String>> phoneAndContentMap) {
//        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append("[");
//        for (Map<String, SmsCodeType> stringSmsCodeTypeMap : phoneAndContentMap.keySet()) {
//            if (stringSmsCodeTypeMap.size() == 1) {
//                for (SmsCodeType value : stringSmsCodeTypeMap.values()) {
//                    stringBuilder.append("'" + value.signName + "',");
//                }
//            } else {
//                throw new ArrayIndexOutOfBoundsException();
//            }
//        }
//        return stringBuilder.substring(0, stringBuilder.length() - 1) + "]";
//    }
//
//    /**
//     * 把批量发送短信的短信内容进行排版，排成阿里云要求的格式
//     *
//     * @param phoneAndContentMap 短信参数名和对应的内容
//     * @return
//     */
//    private static String parsingValue(Map<Map<String, SmsCodeType>, Map<String, String>> phoneAndContentMap) {
//        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append("[");
//        for (Map<String, SmsCodeType> key : phoneAndContentMap.keySet()) {
//            stringBuilder.append(parsingKeyValue(phoneAndContentMap.get(key)) + ",");
//        }
//        return stringBuilder.substring(0, stringBuilder.length() - 1) + "]";
//    }

    // =========================排版===========================================

    // ==========================参数校验==================================

    /**
     * 校验发送单一短信请求参数
     * @param smsRequest
     */
    public static void validatedRequest(SmsRequest smsRequest){
        if(StringUtils.isBlank(smsRequest.getAccessKeyID())){
            throw new ServiceException("accessKeyID不能为空");
        }
        if(StringUtils.isBlank(smsRequest.getAccessKeySecret())){
            throw new ServiceException("accessKeySecret不能为空");
        }
        if(StringUtils.isBlank(smsRequest.getPhoneNumber())){
            throw new ServiceException("手机号不能为空");
        }
        if(StringUtils.isBlank(smsRequest.getSignName())){
            throw new ServiceException("签名不能为空");
        }
        if(StringUtils.isBlank(smsRequest.getTemplateCode())){
            throw new ServiceException("模板code不能为空");
        }
        if(smsRequest.getMapContent().isEmpty()){
            throw new ServiceException("短信内容不能为空");
        }
    }

    /**
     * 校验批量发送短信请求参数
     * @param batchSmsRequest
     */
    public static void validatedBatchRequest(BatchSmsRequest batchSmsRequest){
        if(StringUtils.isBlank(batchSmsRequest.getAccessKeyID())){
            throw new ServiceException("accessKeyID不能为空");
        }
        if(StringUtils.isBlank(batchSmsRequest.getAccessKeySecret())){
            throw new ServiceException("accessKeySecret不能为空");
        }
        if(StringUtils.isNull(batchSmsRequest.getPhoneNumber())){
            throw new ServiceException("手机号不能为空");
        }
        if(StringUtils.isNull(batchSmsRequest.getSignName())){
            throw new ServiceException("签名不能为空");
        }
        if(StringUtils.isBlank(batchSmsRequest.getTemplateCode())){
            throw new ServiceException("模板code不能为空");
        }
        if(batchSmsRequest.getMapContent().isEmpty()){
            throw new ServiceException("短信内容不能为空");
        }
    }

    /**
     * 校验短信发送历史查询请求参数
     * @param hisRequest
     */
    public static void validatedHisRequest(SendHisRequest hisRequest) {
        if(StringUtils.isBlank(hisRequest.getAccessKeyID())){
            throw new ServiceException("accessKeyID不能为空");
        }
        if(StringUtils.isBlank(hisRequest.getAccessKeySecret())){
            throw new ServiceException("accessKeySecret不能为空");
        }
        if(StringUtils.isBlank(hisRequest.getPhoneNumber())){
            throw new ServiceException("手机号不能为空");
        }
        if(StringUtils.isBlank(hisRequest.getSendDate())){
            throw new ServiceException("日期不能为空");
        }
        if(StringUtils.isNull(hisRequest.getCurrentPage()) || StringUtils.isNull(hisRequest.getPageSize())){
            throw new ServiceException("分页条件不能为空");
        }
        if(hisRequest.getCurrentPage()<1 || hisRequest.getPageSize()<1){
            throw new ServiceException("分页条件不正确");
        }
    }

    /**
     * 校验短信签名申请请求参数
     * @param signNameRequest
     */
    public static void validatedSignNameRequest(SignNameRequest signNameRequest) {
        if(StringUtils.isBlank(signNameRequest.getAccessKeyID())){
            throw new ServiceException("accessKeyID不能为空");
        }
        if(StringUtils.isBlank(signNameRequest.getAccessKeySecret())){
            throw new ServiceException("accessKeySecret不能为空");
        }
        if(StringUtils.isBlank(signNameRequest.getSignName())){
            throw new ServiceException("签名名称不能为空");
        }
        if(StringUtils.isNull(signNameRequest.getSmsSignSourceType())){
            throw new ServiceException("签名类型不能为空");
        }
        if(StringUtils.isBlank(signNameRequest.getRemark())){
            throw new ServiceException("说明不能为空");
        }
        if(StringUtils.isNull(signNameRequest.getMultipartFile())){
            throw new ServiceException("图片不能为空");
        }
    }

    /**
     * 校验短信模板申请请求参数
     * @param templateNameRequest
     */
    public static void validatedTemplateNameRequest(TemplateNameRequest templateNameRequest) {
        if(StringUtils.isBlank(templateNameRequest.getAccessKeyID())){
            throw new ServiceException("accessKeyID不能为空");
        }
        if(StringUtils.isBlank(templateNameRequest.getAccessKeySecret())){
            throw new ServiceException("accessKeySecret不能为空");
        }
        if(StringUtils.isBlank(templateNameRequest.getTemplateName())){
            throw new ServiceException("模板名称不能为空");
        }
        if(StringUtils.isNull(templateNameRequest.getSmsTemplateType())){
            throw new ServiceException("模板类型不能为空");
        }
        if(StringUtils.isBlank(templateNameRequest.getTemplateContent())){
            throw new ServiceException("模板格式内容不能为空");
        }
        if(StringUtils.isBlank(templateNameRequest.getRemark())){
            throw new ServiceException("说明不能为空");
        }
    }

    // ==========================参数校验==================================

}
